<template>
  <div>
    <label>{{selectName}}</label>
    <select v-bind:name="selectName" v-bind:id="selectId" v-model="sex">
      <option value>-----请选择-----</option>
      <option v-for="(item,index) in options" v-bind:value="item.val" v-text="item.key">选项一</option>
    </select>
   
  </div>
</template>


<script>
export default {
  name: "SelectV2",
  props: {
    options: {
      type: Array
    },
    selectName: String,
    selectId: String
  },
  data() {
    return {
      sex: ""
    };
  },
  mounted() {},
  methods: {
    test() {},
    getdata1(data){
      console.log("~~~~~~~~~~selectv2~~~~getdat1~~~~~~~~");
    }
  },
  watch: {
    // 监听数据变化
    sex(val) {
      //函数名称就是sex字段名称
      console.log("val:" + val);

      this.$emit('getVal',val); //  这样子明显不方便

      // this.$emit('onSelectV2Change',val);
      // this.$store,commit('',);
      // this.$store.commit('getdata2',{name:'111'});

      this.$store.state.data1 = {'name':'tom'+val};

    }
  }
};
</script>

<style scoped>
</style>